//主栏添加条件
function writeCondition_zl(text){
	var tc = Ext.getDom("selColumnCondition_simple_conditions_zl");
    var tclen = tc.value.length;
    tc.focus();
    if(typeof document.selection != "undefined")
    {
        document.selection.createRange().text = text;  
    }
    else
    {
        tc.setValue(tc.value.substr(0,tc.selectionStart)+text+tc.value.substring(tc.selectionStart,tclen));
    }
}
//修改主栏条件
function updateDimensionConditionWin(ev){
	var conditionWin =  Ext.getCmp('customH_win_conditions_zl');
	if(conditionWin == null || !conditionWin.isVisible())
			conditionWin = new Ext.Window({
				width:600,	
				height: 500,
				layout: "border",
				title:'添加主栏自定义查询条件',
				evObject:null,
				modal: true,
				border:false,
				id: "customH_win_conditions_zl",
				closeAction: 'close',
				defaults:{animate:false},
				listeners:{show:function(a){
				var customDropTarget2 = new Ext.dd.DropTarget(Ext.getCmp('selColumnCondition_simple_div_conditions_zl').getEl().dom, {
					ddGroup: 'customDDGroup',
					copy: false,
					notifyDrop: function(ddSource, e, data){
					node = ddSource.dragData.node;
					if(typeof(node.attributes.column) == 'undefined'){
						return false;
					}
					var a=Ext.getCmp('selColumnCondition_simple_conditions_zl');
					if(node.attributes.d == 'h'){
						a.setValue(a.getValue()+'$'+node.attributes.table+'.'+node.attributes.column);
					}else if(node.attributes.d == 'v'){
						if(node.attributes.tree == true){
							a.setValue(a.getValue()+'$'+node.attributes.table+'.path_' + " like '% " + node.attributes.val + " %'");
						}else{
							a.setValue(a.getValue()+'$'+node.attributes.table+'.'+node.attributes.column + " = '" + node.attributes.val + "'");
						}
					}
					return(true);
				}
				});
			}},
			items: [
			        {
			        	height:608,
			        	width:200,
			        	autoScroll: true,
			        	collapsible: true,
			        	id: 'tree-panel-conditions_zl',
			        	region: 'west',
			        	title: '指标分类',
			        	enableDrag:true,
			        	ddGroup: 'customDDGroup',
			        	split: true,
			        	xtype: 'treepanel',
			        	margins: '2 2 2 2',
			        	useArrows:true,
			        	rootVisible : false,
			        	root: {text: '指标分类',draggable: false,id: '-1',isRoot:true},
			        	loader: new Ext.tree.TreeLoader({
			        		autoLoad:false,
			        		dataUrl: '${pageContext.request.contextPath}/summaryReport.report?decorate=no',
			        		listeners:{beforeload:function(treeLoader, node){
				        		if(node.attributes.isRoot==true){
									this.baseParams.method = "getRoot";
								}else{
									this.baseParams.method = "getChilds";
									this.baseParams.notOnlyNumber = true;
								}
								this.baseParams.xmlId = xml_id_;
								this.baseParams.tableName = node.attributes.table;
								this.baseParams.pid = node.attributes.val;
								this.baseParams.level = node.attributes.level;
								this.baseParams.dir = node.attributes.d;
								this.baseParams.time = node.attributes.time;
								this.baseParams.currentTime = jQuery("#currentTime").val();
								this.baseParams.currentTimeWeiBiao = jQuery("#currentTimeWeiBiao").val();
			        	}}
			        	}),
			        	listeners:{
			        		beforeappend:function(tree,parent,node){
			        	}
			        	}
			        }
			        ,{
			        	region:'center',
			        	height:608,
			        	width:400, 
			        	margins: '2 2 0 2',
			        	title:'添加查询条件',
			        	buttons:[{
				        	text:'保存',
				        	handler:function(){
				        		ev.conditions=Ext.getCmp("selColumnCondition_simple_conditions_zl").getValue();
				        		Ext.getCmp('customH_win_conditions_zl').close();
			        		}
			        	},{
				        	text:'关闭',
				        	handler:function(){
				        		Ext.getCmp('customH_win_conditions_zl').close();
			        		}
			        	}],
			        	buttonAlign:'right',
			        	defaults:{margins: '2 2 2 2'},
			        	bodyStyle:'padding:5px 5px 0',
			        	items:[{
			        		xtype:'fieldset',
			        		title: '添加查询条件',
			        		margins: '2 2 2 2',
			        		collapsible: true,
			        		layout:'form',
			        		frame:true,
			        		defaults:{labelWidth:60,border:false},
			        		items:[{
			        			id:'selColumnCondition_simple_div_conditions_zl',
			        			layout:'form',
			        			items:[
				        		 {
						            xtype: "textarea",
						            id: "selColumnCondition_simple_conditions_zl",
						            width  : 260,
						            height : 140,
						            enableKeyEvents: true,
						            fieldLabel:'查询条件',
						            allowBlank:false,
						            blankText:'自定义列表达式不能为空',
						            colspan:5,
						            value:ev.conditions,
						            style: {
				        			 	marginBottom: '10px',
						                imeMode:'disabled'		//屏蔽输入法
						            },
						            listeners:
					            	{
					            		'render':function(e)
					            		{
					            			//屏蔽粘贴和鼠标右键
					            			//Ext.get('selColumnSql_').dom.oncontextmenu = function(e){return false;};
					            			//Ext.get('selColumnSql_').dom.onpaste = function(e){return false;};
					            		}
					            		,'keypress':function(e)
					            		{//屏蔽键盘按键
											//event.keyCode = 0;
											//event.returnvalue = false;
					            		}
					            		
					            	}
						        }]
			        		},					{
			        			layout: 'table',
			        			border:false,
			        			height: 450,
			        			bodyStyle:'padding:10px 10px 10px 20px',
			        			layoutConfig: {columns:5},
			        			defaults:{frame:false,style:'padding:2px',minWidth: '60',style:{marginBottom: '10px'}},
			        			items:[{
				     			    	   xtype: "button",
				    			    	   text: "and",
				    			    	   style:
				    			    	   {
				    			    	   marginBottom: '5px'
				    			    	   },
				    			    	   handler: function(){
				    			    		   writeCondition_zl("and");
				    			    	   }
				    			       },{
				    			    	   xtype: "button",
				    			    	   text: "or",
				    			    	   style:
				    			    	   {
				    			    	   marginBottom: '5px'
				    			    	   },
				    			    	   handler: function(){
				    			    		   writeCondition_zl("or");
				    			    	   }
				    			       },{
			        			    	   xtype: "button",
			        			    	   text: "substr",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl("substr()");
			        			    	   }
			        			       }
			        			       , {
			        			    	   xtype: "button",
			        			    	   text: "trim",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl("trim()");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: "replace",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl("replace()");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: " <b>Clean</b> ",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   Ext.getCmp("selColumnCondition_simple_conditions_zl").setValue('');
			        			    	   }
			        			       }
			        			       , {
			        			    	   xtype: "button",
			        			    	   text: " + ",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" + ");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: "nvl",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl("nvl()");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: "round",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl("round()");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: "decode",
			        			    	   handler: function(){
			        			    	   writeCondition_zl("decode()");
			        			       }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: "'",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl("'");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: " - ",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" - ");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: "is not null",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" is not null ");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: "is null",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" is null ");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: "not in",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" not in() ");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: "like",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" like '%%' ");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: " * ",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" * ");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: " > ",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" > ");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: " < ",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" < ");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: " = ",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" = ");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: " ( ) ",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" (  ) ");
			        			    	   }
			        			       }
			        			       ,{
			        			    	   xtype: "button",
			        			    	   text: " / ",
			        			    	   style:
			        			    	   {
			        			    	   marginBottom: '5px'
			        			    	   },
			        			    	   handler: function(){
			        			    		   writeCondition_zl(" / ");
			        			    	   }
			        			       }
			        			       ]
			        		}]
			        	}]
			        }
			        ]
			});
	conditionWin.show();
}
	
